﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using RichLabelSpace.Warp;

namespace RichLabelSpace
{
    public class RichLabelMgr
    {
        // 简易对象池
        private static List<RichLabelCtrl> m_ctrl_list = new List<RichLabelCtrl>();

        // 创建一个richlab,并且返回richlabctrl的对象
        // 调用者需要自行清理ctrl
        public static RichLabelCtrl CreateNewRichLab(string rich_txt, Transform mnt, Vector2 size, NGUIText.Alignment alignment, OnClickCallBack call_back)
        {
            //if (m_ctrl_list.Count > 0)
            //{
            //    foreach (var ctrl in m_ctrl_list)
            //    {
            //        if (ctrl.IsBusy)
            //        {
            //            ctrl.Create(rich_txt, mnt, size, alignment, call_back);
            //            return ctrl;
            //        }
            //    }
            //}
            Test.BeginSample("BeginCreate");
            var rich_ctrl = RichLabelCtrl.CreateRichLabelCtrl();
            rich_ctrl.Create(rich_txt, mnt, size, alignment, call_back);
            m_ctrl_list.Add(rich_ctrl);
            Test.EndSample("BeginCreate");
            return rich_ctrl;
        }
    }
}
